package jerry.html.data.convertors;

import java.util.List;

import jerry.html.data.Stuff;
import jerry.html.events.EvtCap;
import jerry.html.events.ItmActivEvtCapImpl;
import jerry.html.events.ItmDeactiveEvtCapImpl;
import jerry.html.events.ItmGetEvtCapImpl;
/**
 * 
 * used to convert stuff data related to game
 * 
 * 
 * @author (h0t@_G0|i
 * 
 */
public class StuffDataConvertor extends DataConvertor{

	@SuppressWarnings("unchecked")
	@Override
	public boolean convertData(List<? extends EvtCap> eventData) {
		boolean flag=false;
		if(dataType.equals(ItmGetEvtCapImpl.class)) {
			for (ItmGetEvtCapImpl evtCap : (List<ItmGetEvtCapImpl>)eventData) {
				Stuff stuff = getPlayerStuff(evtCap.playerId, evtCap.itemName, getStuffType(evtCap.itemName));
				stuff.setPickupTime(evtCap.getTimeStamp());
				stuff.setTimesPicked(stuff.getTimesPicked() + 1);
			}
			flag=true;
		}
		if(dataType.equals(ItmActivEvtCapImpl.class)) {
			for (ItmActivEvtCapImpl evtCap : (List<ItmActivEvtCapImpl>)eventData) {
				Stuff stuff = getPlayerStuff(evtCap.playerId, evtCap.itemName, getStuffType(evtCap.itemName));
				stuff.setTimeOfUse(stuff.getTimeOfUse()-evtCap.getTimeStamp());
			}
			flag=true;
		}
		if(dataType.equals(ItmDeactiveEvtCapImpl.class)) {
			for (ItmDeactiveEvtCapImpl evtCap : (List<ItmDeactiveEvtCapImpl>)eventData) {
				Stuff stuff = getPlayerStuff(evtCap.playerId, evtCap.itemName, getStuffType(evtCap.itemName));
				stuff.setTimeOfUse(stuff.getTimeOfUse()+evtCap.getTimeStamp());
			}
			flag = true;
		}
		return flag;
	}



}
